home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / オンラインウェア / UTIL / Acme Filters 2.3.2 folder.sit / Acme Filters 2.3.2 folder / Acme Filters 2.3.2 / Acme Filters オ / Sources / ASCToMac.c < prev    next >
Text File  |  1996-03-02  |  2KB  |  101 lines

  1. /************ I N C L U D E   F I L E S *******************************************************/
  2.  
  3. #include <stdio.h>
  4. #include <string.h>
  5.  
  6. #include "Acme Filters.h"
  7. #include "ASCToMac.h"
  8.  
  9.  
  10.  
  11. /**********************************************************************************************
  12.  * Function Name:  ASCToMac
  13.  *
  14.  * Description:    Convert Donna's Smith-Corona word processor files (ASCII format)
  15.  *                 to Mac-readable files (WriteNow text files).
  16.  *
  17.  * Parameters:     iFile - file spec of a file.
  18.  *
  19.  * Return Value:   None.
  20.  **********************************************************************************************/
  21. void    ASCToMac( FSSpec *iFile )
  22. {
  23.     FILE    *iFp, *oFp;
  24.     char    iBuf[kBufSize];
  25.     char    *c;
  26.     FSSpec    oFile;
  27.     FInfo    oInfo;
  28.     Boolean    topOfDoc = true;
  29.     Str255    oName;
  30.     
  31.     // create and open the output file
  32.     FSMakeFSSpec( iFile->vRefNum, iFile->parID, iFile->name, &oFile );
  33.     if ( oFile.name[0] > kMaxName ) oFile.name[0] = kMaxName;
  34.     pstrcat( oFile.name, "¥p.mac" );
  35.     pstrcpy( oName, oFile.name );            // save the real name
  36.     pstrcpy( oFile.name, kTempFileName );    // use a temporary name
  37.     oFp = FSpfopen( &oFile, "wb" );
  38.     
  39.     // set the output file's type and creator
  40.     FSpGetFInfo( &oFile, &oInfo );
  41.     oInfo.fdType = kTEXTType;
  42.     oInfo.fdCreator = kWNCreator;
  43.     FSpSetFInfo( &oFile, &oInfo );
  44.     
  45.     // filter the input file
  46.     if ( iFp = FSpfopen( iFile, "rb" ) )
  47.     {
  48.         while ( fgets( iBuf, kBufSize-1, iFp ) != nil )
  49.         {
  50.             gCancelReq |= Cancel();
  51.             ScrollIcon();
  52.             c = iBuf;
  53.             while ( *c )
  54.             {
  55.                 // replace 5 leading spaces (indented paragraph) with 2 carriage returns and a tab
  56.                 if ( (strncmp( kFiveSpaces, c, kPSpaces ) == 0) && (*(c+kPSpaces) != kSpace) )
  57.                 {
  58.                     if ( topOfDoc )
  59.                     {
  60.                         topOfDoc = false;
  61.                     }
  62.                     else
  63.                     {
  64.                         fputc( kCR, oFp );
  65.                         fputc( kCR, oFp );
  66.                     }
  67.                     fputc( kTab, oFp );
  68.                     c += kPSpaces;
  69.                 }
  70.                 // replace carriage return/line feed with a space
  71.                 else if ( (*c == kCR) && (*(c+1) == kLF) )
  72.                 {
  73.                     fputc( kSpace, oFp );
  74.                     c += 2;
  75.                 }
  76.                 // skip these characters
  77.                 else if ( (*c == kFF) )
  78.                 {
  79.                     c++;
  80.                 }
  81.                 // let everything else pass thru
  82.                 else
  83.                 {
  84.                     fputc( *c, oFp );
  85.                     c++;
  86.                 }
  87.             }
  88.         }
  89.     }
  90.     
  91.     // close the files
  92.     if ( iFp ) fclose( iFp );
  93.     if ( oFp ) fclose( oFp );
  94.     
  95.     // set the real filename and deal with any conflicts
  96.     while ( FSpRename( &oFile, oName ) == dupFNErr )
  97.         oName[oName[0]]++;
  98.     
  99.     TickleParentDir( &oFile );
  100. }
  101.